package api

import (
	"easyShop/services"
	"github.com/gin-gonic/gin"
)

type UploadController struct {
}

func (p UploadController) UploadImage(c *gin.Context) {
	// 单文件
	file, _ := c.FormFile("file")

	savePath, err := services.UploadImage(file, c)
	if err != nil {
		c.JSON(500, gin.H{
			"code": 500,
			"msg":  err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"data": gin.H{"path": savePath},
		"msg":  "uploaded",
	})
	//c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
}
